package com.baosight.risk.web.xtdc;

import com.baosight.risk.api.xtdc.XtdcAttachService;
import com.baosight.risk.api.xtdc.XtdcDirectoryService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.common.file.FileManager;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.service.xtdc.entity.XtdcDirectory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;

/**
 * @author houji
 */
@Slf4j
@RestController
@RequestMapping("xtdc/directory")
@Api(value = "目录", description = "目录", produces = MediaType.APPLICATION_JSON)
public class XtdcDirectoryController extends BaseController {
    @Autowired
    private FileManager fileManager;
    @Autowired
    private XtdcDirectoryService xtdcDirectoryService;
    @Autowired
    private XtdcAttachService xtdcAttachService;

    @GetMapping("/addDirectory")
    @ApiOperation("新建文件夹")
    public AjaxResult addDirectory(XtdcDirectory xtdcDirectory) {
        log.info("创建文件夹....");
        Integer integer = xtdcDirectoryService.addDirectory(xtdcDirectory);
        return toAjax(integer);
    }

    @GetMapping("/selectList")
    @ApiOperation("获取团队根目录")
    public AjaxResult selectList(@RequestParam("rootDocId") String rootDocId) {
        return success(xtdcDirectoryService.selectList(rootDocId));
    }

    @GetMapping("selectChildList")
    public AjaxResult selectChildList(XtdcDirectory xtdcDirectory) {
        return success(xtdcDirectoryService.selectChildList(xtdcDirectory));
    }

    @GetMapping("deleteDir")
    public AjaxResult deleteDir(@RequestParam("teamId") String teamId, @RequestParam("dirId") String dirId) {
        Integer integer = xtdcDirectoryService.deleteDir(teamId, dirId);
        if (integer == 0) {
            return error("没有权限删除文件夹！");
        }
        return success();
    }
}
